#include "CoCoA/library.H"
#include <iostream>
#include <cstdlib>
using namespace CoCoA;
using namespace std;

enum mytype {POLY, STRING};
class poly_or_string {
		public:
				poly_or_string(void* data, mytype flag): __flag(flag) {
				
					switch(__flag) {
							case STRING:
									__data=new string(*(string*)data);
									break;
							case POLY:
									__data=new RingElem(*(RingElem*)data);
									break;
					}
				}

				~poly_or_string(){
					
					switch(__flag) {
							case STRING:
									delete (string*)__data;
									break;
							case POLY:
									delete (RingElem*)__data;
									break;
					}

				}

		private:
				void* __data;
				mytype __flag;

};

RingElem randpoly() {
	SparsePolyRing R = NewPolyRing(RingQ(), symbols("x","y"));
	return rand() * indet(R,0) + 	rand() * indet(R,1);
}


int main(){
	CoCoA::GlobalManager CoCoAFoundations;
	srand((unsigned long)&CoCoAFoundations);
	SparsePolyRing R = NewPolyRing(RingQ(), symbols("x","y"));
	RingElem* p=new RingElem(R);
	RingElem* q=new RingElem(indet(R,1));
	cout << *p << endl;
	cout << *q << endl;
	poly_or_string pw(p, POLY), qw(q,POLY);
	RingElem poly=randpoly();
	cout << poly << endl;
	return 0;
}
